package com.sk.cardeal.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.sk.cardeal.R;


/**
 * Created by sk on 2017/11/21.
 */

public class LineMenuView extends RelativeLayout {

    private TextView tvTitle;
    private TextView tvHint;
    private int hintColor;

    @RequiresApi(api = Build.VERSION_CODES.M)
    public LineMenuView(Context context, AttributeSet attrs) {
        super(context, attrs);
        LayoutInflater.from(context).inflate(R.layout.item_menu, this);

        tvTitle = findViewById(R.id.tv_title);
        tvHint = findViewById(R.id.tv_hint);
        ImageView more = findViewById(R.id.more);

        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.lmvattr);
        int count = ta.getIndexCount();
        for (int i = 0; i < count; i++) {
            int itemId = ta.getIndex(i);
            switch (itemId) {
                case R.styleable.lmvattr_hint:
                    setHint(ta.getString(itemId));
                    break;
                case R.styleable.lmvattr_tip:
                    setTitle(ta.getString(itemId));
                    break;
                case R.styleable.lmvattr_hintColor:
                    setHintColor(ta.getColor(itemId,getResources().getColor(R.color.hint_color,null)));
                    break;
                case R.styleable.lmvattr_lmvattrVisiable:
                    boolean canSee = ta.getBoolean(itemId, true);
                    if (canSee) {
                        more.setVisibility(VISIBLE);
                    } else {
                        more.setVisibility(INVISIBLE);
                    }
                    break;
            }
        }
    }

    public int getHintColor() {
        return hintColor;
    }

    public String getHint(){
        return tvHint.getText().toString();
    }

    public void setHintColor(int hintColor) {
        tvHint.setTextColor(hintColor);
    }

    // 设置hint
    public void setHint(String hint) {
        tvHint.setText(hint);
    }

    // 设置标题
    public void setTitle(String title) {
        tvTitle.setText(title);
    }

}
